package com.example.android.ouactivity;

import android.content.Intent;
import android.support.v7.app.ActionBar;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.DividerItemDecoration;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.MenuItem;
import android.view.View;
import android.widget.Toast;

import com.example.android.ouactivity.adapter.MessageViewAdapter;
import com.example.android.ouactivity.adapter.SystemMsgAdapter;

/**
 * create by chqing 消息列表
 * add Home and View title 11.17
 */
public class MessageActivity extends AppCompatActivity {
    private RecyclerView recyclerView;
    private RecyclerView.LayoutManager layoutManager;
    private String[] datas = {"我的回复","系统通知"};
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_message);
        //设置返回，及页面标题
        ActionBar actionBar = getSupportActionBar();
        if (actionBar != null) {
            actionBar.setDisplayHomeAsUpEnabled(true);
        }
        if (actionBar != null) {
            actionBar.setTitle("我的消息");
        }

        recyclerView = (RecyclerView)findViewById(R.id.my_msg_view);
        //创建默认的线性LayoutManager
        layoutManager = new LinearLayoutManager(this,LinearLayoutManager.VERTICAL,false);
        recyclerView.setLayoutManager(layoutManager);
        //如果可以确定每个item的高度是固定的，设置这个选项可以提高性能
        recyclerView.setHasFixedSize(true);
        //添加分割线
        recyclerView.addItemDecoration(new DividerItemDecoration(this,DividerItemDecoration.VERTICAL));
        //创建并设置Adapter
        MessageViewAdapter msgAdapter = new MessageViewAdapter(datas);
        recyclerView.setAdapter(msgAdapter);
        //设置监听事件
        msgAdapter.setOnItemClickListener(new MessageViewAdapter.OnItemClickListener() {
            @Override
            public void onItemClick(View view, int position) {
                switch (position){
                    case 0:
                        Intent comm = new Intent(MessageActivity.this,CommentReplyActivity.class);
                        startActivity(comm);
                        break;
                    //测试
                    case 1:
                        Intent sys = new  Intent(MessageActivity.this, SystemMsgActivity.class);
                        startActivity(sys);
//                       Toast.makeText(MessageActivity.this,"待续",Toast.LENGTH_SHORT).show();
                        break;
                }
            }
        });
    }
    //左上角返回的监听
    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        switch (item.getItemId()){
            case android.R.id.home:
                finish();
                break;
        }
        return super.onOptionsItemSelected(item);
    }
}
